<template>
  <div>
    <ul class="bill-item">
      <!--商品图片-->
      <li class="item-img" :class="{'width-280': giftsExist}">
        <!--商品-->
        <div class="item-table-cell">
          <img :src="item.icon1" :title="item.name" :alt="item.name" />
        </div>
        <!--赠品-->
        <div class="item-table-cell" :class="{'padding-left-18': giftsExist}" v-if="giftsExist">
          <img :src="item.gives[0].icon1" :title="item.gives[0].goods_name" :alt="item.gives[0].goods_name" />
        </div>
        <div class="item-table-cell" :class="{'width-102': giftsExist}" v-if="giftsExist"></div>
      </li>
      <!--商品名-->
      <li class="item-title" v-if="!giftsExist">
        <div class="item-table-cell">
          <p>{{ item.name }} {{ item.sub_name }}</p>
        </div>
      </li>
      <li class="item-number">
        <div class="item-table-cell">
          <!--已还账单-->
          <span v-if="item.type === 0">{{$t('message.divide')}}</span>{{ item.stages }}{{$t('message.time')}}
        </div>
      </li>
      <li class="item-pay">
        <div class="item-table-cell">
          <!--已还账单-->
          <div v-if="item.type === 0" class="item-money-pay">
            {{ $t('message.currencySymbol') }}{{ item.staging_price }}
          </div>
          <!--待还账单-->
          <div v-else>
            <div class="item-money-pay">
              {{ $t('message.currencySymbol') }}{{ item.amount }}
            </div>
            <div class="item-money-overdue" v-if="item.state > 0">
              <div class="icon-question" @mouseenter="showOverdueTip" @mouseleave="hideOverdueTip"></div>
              <div class="item-money-tip" v-if="showTip">
                <div class="icon-angle-up"></div>
                {{$t('message.PersonalBillRepayTimeFee')}}：{{ $t('message.currencySymbol') }}{{ item.late_fee }}
              </div>
            </div>
          </div>
        </div>
      </li>
      <li class="item-date">
        <div class="item-table-cell">
          <!--已还账单-->
          <template v-if="item.type === 0">{{ $t('message.currencySymbol') }}{{ item.total_price }}</template>
          <!--待还账单-->
          <template v-else>{{ item.last_pay_date }}</template>
        </div>
      </li>
      <li class="item-status">
        <!--已还账单-->
        <div v-if="item.type === 0" class="item-table-cell">
          {{$t('message.hasPay2')}}
        </div>
        <!--待还账单-->
        <div v-else class="item-table-cell" :class="{ 'item-status-warning': isTextWarning }">
          <!--已还款-->
          <template v-if="item.state === -1">
            {{ $t('message.hasPay2') }}
          </template>
          <!--待还款-->
          <template v-if="item.state === 0">
            {{ $t('message.waitForPay') }}
          </template>
          <!--逾期x天-->
          <template v-if="item.state > 0">
            {{ $t('message.overTime') }}{{ item.state }}{{ $t('message.day') }}
          </template>
        </div>
      </li>
      <li class="item-operation">
        <div class="item-table-cell">
          <!--待还账单-->
          <template v-if="item.type === 1">
            <div class="link-pay">
              <!--立即还款-->
              <router-link :to="{path: 'repay', query: {orderId: item.id}}" target="_blank">{{ $t('message.PersonalBillRepayReturnNow') }}</router-link>
            </div>
          </template>
          <!--已还账单-->
          <template>
            <!--账单明细-->
            <div class="link-detail" @click="toBillDetail">{{ $t('message.billDetail') }}</div>
          </template>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>

export default {
  name: 'PersonalBillItem',
  props: {
    item: {
      type: Object,
      default () {
        return {
          month: ''
        }
      }
    },
    type: {
      type: String,
      default: 'notPay'
    },
    giftsExist: {
      type: Boolean,
      default: false
    }
  },
  data () {
    return {
      showTip: false
    }
  },
  computed: {
    isTextWarning () {
      if (this.item.state <= 0) {
        return false
      } else {
        return true
      }
    }
  },
  methods: {
    showOverdueTip () {
      this.showTip = true
    },
    hideOverdueTip () {
      this.showTip = false
    },
    toBillDetail () {
      this.$router.push({ path: 'detail', query: { orderId: this.item.id } })
    }
  }
}
</script>

<style scoped>
.bill-item {
  height: 128px;
}

.bill-item:after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  clear: both;
  visibility: hidden;
}

.bill-item li {
  float: left;
  height: 128px;
  display: table;
  font-size: 14px;
}

.item-table-cell {
  display: table-cell;
  vertical-align: middle;
}

.item-img {
  width: 80px;
}

.item-img > div {
  width: 80px;
  height: 80px;
}

.item-img img {
  width: 80px;
  height: 80px;
}

.item-title {
  width: 200px;
}

.item-title > div {

}

.item-title p {
  width: 142px;
  line-height: 20px;
  padding-left: 8px;
  color: #333;
}

.item-number {
  width: 106px;
}

.item-pay {
  width: 118px;
}

.item-money-pay {
  float: left;
}

.item-money-overdue {
  float: left;
  margin-left: 5px;
  position: relative;
}

.icon-question {
  width: 14px;
  height: 14px;
  background: url(../../../assets/images/personal/icon_question_tip.png) no-repeat center;
  cursor: pointer;
  margin-top: 3px;
}

.item-money-tip {
  height: 41px;
  line-height: 39px;
  padding: 0 11px;
  white-space: nowrap;
  border: 1px solid #e6e6e6;
  background-color: #fff;
  font-size: 12px;
  text-align: center;
  color: #666;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  -ms-transform: translateX(-50%);
  margin-top: 14px;
}

.icon-angle-up {
  height: 0;
  width: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid #e6e6e6;
  position: absolute;
  top: -7px;
  left: 50%;
  margin-left: -4px;
}

.icon-angle-up:after {
  content: '';
  display: block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 6px solid #fff;
  position: absolute;
  top: 1px;
  left: -4px;
}

.item-date {
  width: 148px;
}

.item-status {
  width: 118px;
}

.item-status-warning {
  color: #e74c3c;
}

.item-operation {
  width: 94px;
}

.item-operation div {
  line-height: 17px;
  font-size: 12px;
}

.item-operation a {
  color: #ff600a;
}

.link-pay {
  color: #ff600a;
  margin-bottom: 12px;
}

.link-detail {
  color: #ff600a;
  cursor: pointer;
}

.link-detail:hover, .link-pay:hover {
  text-decoration: underline;
}

.padding-left-18 {
  padding-left: 18px;
}

.width-280 {
  width: 280px;
}

.width-102 {
  width: 102px;
}
</style>
